package antrace;

import processing.core.PFont;
import processing.core.PMIDlet;
import processing.phone.Phone;

public class AntRace extends PMIDlet {

	public static final int KEY_TWO = 50;
	public static final int KEY_FOUR = 52;
	public static final int KEY_SIX = 54;
	public static final int KEY_EIGHT = 56;
	public static final int KEY_FIVE = 53;
	
	public static final String FILENAME_HIGHSCORE = "highscore.txt";

	public static PFont font; 
	public static PFont selectedFont;
	public static PFont whiteFont; 
	
	Phone phone;

	public static SplashView splash;
	public static GameView game;
	public static MenuView menu;
	public static ViewManager viewManager;

	public static AntRace midlet;

	private static long centralTimer;

	public void setup() {
		// mycket vacker singleton pattern
		midlet = this;
//		behövs för att skapa highscore första gången man kör!
		//try {
//			this.loadStrings(FILENAME_HIGHSCORE);
		//}
//		catch (Exception E) {
		String test[] = {"ERI   19","JOH   12","SOF   123","DAV   321","SVE   666", "BLU   101"};
		this.saveStrings(FILENAME_HIGHSCORE, test);
//		}
		
		font = AntRace.midlet.loadFont("/images/fonts/Acknowledge30.mvlw", AntRace.midlet.color(0));
		selectedFont = AntRace.midlet.loadFont("/images/fonts/Acknowledge30.mvlw", AntRace.midlet.color(89, 150, 199));
		whiteFont = AntRace.midlet.loadFont("/images/fonts/Acknowledge30.mvlw", AntRace.midlet.color(255));
		textFont(font);
		
		// Använd Phone för att kunna visa fullscreen
		phone = new Phone(this);
		phone.fullscreen();

		// starta Views
		splash = new SplashView();
		game = new GameView();
		menu = new MenuView();

		// starta viewManagern med game som startview
		viewManager = new ViewManager(splash);

		// Kör med låst framerate
		framerate(20);
	}

	/**
	 * Rita ut aktuell View
	 */
	public void draw() {
		
		viewManager.drawView();

		centralTimer++;
	}

	public void keyPressed() {
		viewManager.currentView.keyPressed(keyCode);
	}

	public void keyReleased() {
		viewManager.currentView.keyReleased(keyCode);
	}

	public static long getCentralTime() {
		return centralTimer;
	}

	public void quit() {
		exit();
	}
}
